<template>
<div>
    <div >
       <el-button size="small" @click="Addlaber">保存</el-button>
       <el-button size="small" v-if="Yes" @click="examine">提交审批</el-button>
      </div>

    <div >
        <font size="6" bold   style="position:relative;left:700px">劳务付款</font>
      </div>
      <br>
      
<el-form :model="laber"  label-width="100px" class="demo-ruleForm">
    <!-- 第一个表格 -->
    <table class="divtable" width="100%">
        <tr>
            <td colspan="8" class="color">基本信息</td>
        </tr>
        <tr>
            <td class="tabletd">日期:</td>
            <td><el-input type="date" v-model="laber.apply_date"  value-format="yyyy-MM-dd"  ></el-input></td>
            <td class="tabletd">付款编号:</td>
            <td><el-input v-model="laber.id" placeholder="保存后自动生成"  disabled></el-input></td>
            <td class="tabletd">付款名称:</td>
            <td><el-input v-model="laber.payment_name"   clearable></el-input></td>
            <td class="tabletd">源单类型:</td>
            <td>
                <el-select v-model="laber.type" clearable placeholder="请选择">
                    <el-option value="劳务合同">劳务合同</el-option>
                    <el-option value="进度款申报">进度款申报</el-option>
                </el-select>
            </td>
        </tr>
        <tr>
            <td class="tabletd">源单号:</td>
            <td><el-input v-model="laber.ctr_id" @focus="contractname"   clearable></el-input></td>
            <td class="tabletd">所属项目:</td>
            <td><el-input v-model="laber.p_id" disabled></el-input></td>
            <td class="tabletd">劳务班组:</td>
            <td><el-input v-model="laber.company_id"   disabled></el-input></td>
            <td class="tabletd">合同金额:</td>
            <td><el-input   v-model="laber.contract_amount" disabled></el-input></td>
        </tr>
        <tr>
            <td class="tabletd">已付款金额:</td>
            <td><el-input   v-model="laber.advance_pay"  disabled></el-input></td>
            <td class="tabletd">罚款:</td>
            <td><el-input v-model="laber.penalty" type="number" clearable></el-input></td>
            <td class="tabletd">扣款:</td>
            <td><el-input v-model="laber.withhold" type="number" clearable></el-input></td>
            <td class="tabletd">付款类型:</td>
            <td>
                <el-select v-model="laber.settle_type" clearable placeholder="请选择">
                    <el-option value="进度款">进度款</el-option>
                    <el-option value="完工款">完工款</el-option>
                </el-select>
            </td>
        </tr>
        <tr>
            <td class="tabletd">开户银行:</td>
            <td><el-input v-model="laber.bank_id" @focus="bankid"   clearable></el-input></td>
            <td class="tabletd">银行账户:</td>
            <td><el-input v-model="laber.account" disabled></el-input></td>
            <td class="tabletd">付款金额:</td>
            <td><el-input v-model="laber.agree_amount" type="number" @blur="money"  clearable></el-input></td>
            <td class="tabletd">填报人:</td>
            <td><el-input v-model="laber.handler_id" clearable></el-input></td>
        </tr>
        <tr>
            <td class="tabletd">金额大写:</td>
            <td><el-input v-model="laber.agree_upper"  disabled></el-input></td>
            <td class="tabletd"></td>
            <td></td>
            <td class="tabletd"></td>
            <td></td>
            <td class="tabletd"></td>
            <td></td>
        </tr>
        <tr>
            <td class="tabletd">备注:</td>
            <td colspan="7"><el-input v-model="laber.settle_comment" type="textarea" rows="4"  clearable></el-input></td>
        </tr>
        
    </table>

    <multi-file-upload
                style="width: 100%;margin: 20px auto"
                title="附件"
                action="http://localhost/uploads"
                :params="{folder: 'tenderPurchasePlan'}"
                :headers="{token: token}"
                :show-button="!checkRoute"
                @uploadSuccess="handleUploadSuccess"
                :parent-file-list="fileList"
        ></multi-file-upload>

   
</el-form>

<!-- 合同子组件 -->
<el-dialog  :visible.sync="dialogVisible"  width="50%">
<laber-contract v-if="dialogVisible"  @row="LaberContract"></laber-contract>
</el-dialog>

<!-- 银行子组件 -->
<el-dialog  :visible.sync="dialogVisible2"  width="50%">
<bank v-if="dialogVisible2"  @row="Bank"></bank>
</el-dialog>

  </div>
</template>

<script>

import LaberContract from '../common/providerinfo/LaberContract.vue';

import LaoWuHeTong from '@/model/smj/LaoWuHeTong'
 const Laowuhetong= new LaoWuHeTong;

import LaoWuFuKuan from '@/model/smj/LaoWuFuKuan'
const laowufukuan= new LaoWuFuKuan;

import {DateUtil} from "@/model/common/DateUtil";
import Bank from '../common/providerinfo/Bank.vue';



export default {
  name: "LaoWuFuKuan",
  components: {LaberContract, Bank},
  directives: {},
  data() {
    return {
        laber:{
            attach_ids:'',
            apply_date:DateUtil.today(),
            handler_id:sessionStorage.getItem('realName')
        },
        tenderPurchasePlan: {
            id: '',
            date: DateUtil.today(),
            planEditor: sessionStorage.getItem('realName')
        },
        fileList:[],

        laberID:'',//合同id
        projectID:'',//项目id
        providerID:'',//班组id
        bankID:'',//银行id

        dialogVisible:false,
        dialogVisible2:false,
        Yes:false,
    }
  },
  mounted() {},
  methods: {

      //转换器
      toChies(values){//形参
					let len=values.length//统计出长度
					let arr=[];
					
					let chin_list=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']//所有的数值对应的汉字
					
					let chin_lisp=['仟','佰','拾','亿','仟','佰','拾','万','仟','佰','拾']//进制
					
					for(let i=0;i<len;i++){
						arr.push(parseInt(values[i]));		//输入的数据按下标存进去   存进去的只是数字
						arr[i]=chin_list[arr[i]]			//是根据我们输入的输入的数字，对应着我们的chin_list这个数组
					}//123['壹','佰','贰','拾','叁']
					
					for(let i=len-1,j=1;i>0;i--){//i =2	1		//倒序		为了添加进制，方便我们去观看
						arr.splice(i,0,chin_lisp[chin_lisp.length-j++])	//j=2
					}
					console.log(arr)
					
					arr=arr.join('')
					if(len>=1){
						arr+='元整'
					}
					return arr
				},

      //金额转换
      money(){
          var money = this.laber.agree_amount;
          var Maxmoney = this.toChies(money);
          console.log(Maxmoney)
          this.laber.agree_upper=Maxmoney
      },

      //开启合同名称组件
      contractname(){
          this.dialogVisible = true;
      },
      //响应合同组件
      LaberContract(row){
          console.log(row)
          this.laber.ctr_id = row.contract_name
          this.laber.p_id = row.project_name
          this.laber.company_id = row.provider_name
          this.laber.contract_amount= row.contract_amount
          this.laber.advance_pay = row.advance_pay

          this.laberID = row.id
          this.projectID = row.p_id
          this.providerID = row.labor_org_id
           this.dialogVisible = false;
      },

      //开启银行组件
      bankid(){
            this.dialogVisible2 = true;
      },
      Bank(row){
          console.log(row)
          this.laber.bank_id = row.bank_name
          this.laber.account = row.account

          this.bankID = row.bank_id
           this.dialogVisible2 = false;
      },


         //文件上传
        handleUploadSuccess(ids,fileList){
            console.log(fileList)
                this.tenderPurchasePlan.attachemeIds = ids
            },



     

      //添加劳务合同
      Addlaber(){
          console.log(this.laber)
            //判断合同信息不能为空
          if(this.laber.payment_name == '' || this.laber.payment_name == undefined){
                this.$message.error('错误信息,付款名称不能为空');
          }else{
              if(this.laber.type == '' || this.laber.type == undefined){
                this.$message.error('错误信息,源单类型不能为空');
          }else{
              if(this.laber.ctr_id == '' || this.laber.ctr_id == undefined){
                this.$message.error('错误信息,源单号不能为空');
          }else{
              if(this.laber.penalty == '' || this.laber.penalty == undefined){
                this.$message.error('错误信息,罚款不能为空');
          }else{
              if(this.laber.withhold == '' || this.laber.withhold == undefined){
                this.$message.error('错误信息,扣款不能为空');
          }else{
              if(this.laber.settle_type == '' || this.laber.settle_type == undefined){
                this.$message.error('错误信息,付款类型不能为空');
          }else{
              if(this.laber.bank_id == '' || this.laber.bank_id == undefined){
                this.$message.error('错误信息,开户银行不能为空');
          }else{
              if(this.laber.agree_amount == '' || this.laber.agree_amount == undefined){
                this.$message.error('错误信息,付款金额不能为空');
          }else{
              if(this.laber.agree_upper == '' || this.laber.agree_upper == undefined){
                this.$message.error('错误信息,金额大写不能为空');
          }else{
              if(this.laber.handler_id == '' || this.laber.handler_id == undefined){
                this.$message.error('错误信息,填报人不能为空');
          }else{
              if(this.laber.settle_comment == '' || this.laber.settle_comment == undefined){
                this.$message.error('错误信息,备注不能为空');
          }else{
              
                    this.laber.attach_ids=this.tenderPurchasePlan.attachemeIds;
                    console.log(this.laber.attach_ids)
                          laowufukuan.Addlaber(this.laber,this.laberID,this.projectID,this.providerID,this.bankID).then((response)=>{
                              this.$message({ message: '添加成功',  type: 'success' });
                              this.Yes=true;
                              this.laber.id = response.data;
                              if(this.laber.attach_ids != '' || this.laber.attach_ids != undefined){
                                  Laowuhetong.UpdateInfo(this.laber.attach_ids,sessionStorage.getItem('realName')).then(()=>{})
                              }

                          })
                
          }
          }
          }
          }
          }
          }
          }
          }
          }
          }
          }
          
      },

      //提交审批
      examine(){
            laowufukuan.FlowLaberApply(this.laber).then((response)=>{
                if(response.data == 1){
                    this.$message({ message: '提交成功',  type: 'success' });
                     this.Yes=false;
                }else{
                    this.$message.error('提交失败');
                }
                
            }) 
      },

      
  
  },
  computed: {
            token: {
                get() {
                    return this.$store.state.token
                }
            },
            checkRoute(){
                return Object.keys(this.$route.params).length != 0
            }
        },
  created() {
       
  },
  
};
</script>

<style>
.divtable{
    border-collapse:collapse;
}
.divtable td{
    padding:10px;
    border:1px solid rgb(7, 136, 175);
}
.tabletd{
    text-align: right;
    background-color: rgb(113, 222, 241);
}
.color{
    background-color: rgb(113, 222, 241);
}
.divtable2{
    border-collapse:collapse;
}
.divtable2 td{
    padding:10px;
    border:1px solid rgb(7, 136, 175);
}
.td{
    text-align: center;
}
</style>